package mylab.starters.dag.graph.impl;

import com.google.common.collect.Sets;

import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;

import lombok.Getter;
import lombok.Setter;
import mylab.base.foundation.template.pojo.BaseStringIDPojo;
import mylab.starters.dag.graph.Graph;
import mylab.starters.dag.graph.Vertex;

public class BaseVertex extends BaseStringIDPojo implements Vertex {

    @Getter
    @Setter
    protected Graph graph;
    @Getter
    protected Set<Vertex> dependentVertices = Sets.newHashSet();
    @Getter
    protected Set<Vertex> adjacentVertices = Sets.newHashSet();
    protected AtomicInteger indegree;

    public BaseVertex(String id) {
        this(id, id);
    }

    public BaseVertex(String id, String name) {
        this.id = id;
        this.name = name;
    }

    @Override
    public AtomicInteger getIndegree() {
        if (indegree == null) {
            indegree = new AtomicInteger(getDependentVertices().size());
        }
        return indegree;
    }


}
